Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Lazy load mpc core kit #2808

Merged
merged 5 commits into from
Nov 14, 2023
Merged

fix: Lazy load mpc core kit #2808

merged 5 commits into from
Nov 14, 2023

Conversation

usame-algan
Copy link
Member

What it solves

Part of #2452

Lazy loads the mpc core kit to reduce the initial js bundle size

How this PR fixes it

  • Converts the useInitMPC and useInitSocialWallet hooks into functions
  • Uses next/dynamic to import SocialSigner
  • Changes the onboard module to lazy import dependencies

How to test it

  1. Open the safe
  2. Login with social
  3. Observe being logged in
  4. Reload the page
  5. Observe being logged in with social again
  6. Log in with Metamask or any other wallet
  7. Observe it still working

Copy link

github-actions bot commented Nov 14, 2023

Branch preview

✅ Deploy successful!

https://lazyloadmpc--walletweb.review-wallet-web.5afe.dev

Copy link

github-actions bot commented Nov 14, 2023

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

Copy link

github-actions bot commented Nov 14, 2023

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
75.12% (+0.08% 🔼)
10095/13439
🔴 Branches
49.67% (+0.11% 🔼)
2051/4129
🔴 Functions
57.62% (+0.09% 🔼)
1504/2610
🟡 Lines
76.7% (+0.09% 🔼)
9126/11899
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / WalletDetails.tsx
87.5% (-12.5% 🔻)
100% 0%
85.71% (-14.29% 🔻)

Test suite run success

1105 tests passing in 155 suites.

Report generated by 🧪jest coverage report action from a77eb41

export const initMPC = async (chain: ChainInfo, onboard: OnboardAPI) => {
const chainConfig = {
chainId: `0x${Number(chain.chainId).toString(16)}`,
chainNamespace: 'eip155',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please defne this as a const.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably revert this to the constant we were using.

Comment on lines 38 to 50
// If the signer is not in the address book => add the user's email as name
const userInfo = socialWalletService?.getUserInfo()
if (userInfo && wallets && currentChainId && wallets.length > 0) {
const address = wallets[0].accounts[0]?.address
if (address) {
const signerAddress = checksumAddress(address)
if (addressBook[signerAddress] === undefined) {
const email = userInfo.email
dispatch(upsertAddressBookEntry({ address: signerAddress, chainId: currentChainId, name: email }))
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract this into a function (can be within the hook).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link

📦 Next.js Bundle Analysis for safe-wallet-web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 1.4 MB (🟢 -493.28 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Nine Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/addOwner 3.52 KB (🟢 -2 B) 1.4 MB
/balances/nfts 18.63 KB (🟡 +1 B) 1.41 MB
/settings/security-login 14.37 KB (-1 B) 1.41 MB
/settings/setup 24.13 KB (🟢 -3 B) 1.42 MB
/settings/spending-limits 22.72 KB (-1 B) 1.42 MB
/transactions 52.47 KB (🟡 +799 B) 1.45 MB
/transactions/history 52.43 KB (🟡 +799 B) 1.45 MB
/welcome 7.1 KB (🟡 +110 B) 1.4 MB
/welcome/social-login 7.54 KB (🟡 +108 B) 1.4 MB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

Copy link

📦 Next.js Bundle Analysis for safe-wallet-web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 1.4 MB (🟢 -493.27 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Nine Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/addOwner 3.52 KB (🟢 -2 B) 1.4 MB
/balances/nfts 18.63 KB (🟡 +1 B) 1.41 MB
/settings/security-login 14.37 KB (-1 B) 1.41 MB
/settings/setup 24.13 KB (🟢 -3 B) 1.42 MB
/settings/spending-limits 22.72 KB (-1 B) 1.42 MB
/transactions 52.47 KB (🟡 +799 B) 1.45 MB
/transactions/history 52.43 KB (🟡 +799 B) 1.45 MB
/welcome 7.1 KB (🟡 +109 B) 1.4 MB
/welcome/social-login 7.54 KB (🟡 +108 B) 1.4 MB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

Copy link
Member

@schmanu schmanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around with it for a bit.
It works well.
One small issue I encountered is that the login with google button is not displayed / on a fresh page load and also no placeholder.

@usame-algan
Copy link
Member Author

usame-algan commented Nov 14, 2023

One small issue I encountered is that the login with google button is not displayed / on a fresh page load and also no placeholder.

Good catch! next/dynamic supports a custom fallback so I added a skeleton there.

I've also updated the bundle-analyzer action to use the sticky-comment workflow which is set to be released with hashicorp/nextjs-bundle-analysis#54

Copy link

📦 Next.js Bundle Analysis for safe-wallet-web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 1.4 MB (🟢 -493.25 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Nine Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/addOwner 3.52 KB (🟢 -2 B) 1.4 MB
/balances/nfts 18.63 KB (🟡 +1 B) 1.41 MB
/settings/security-login 14.37 KB (-1 B) 1.41 MB
/settings/setup 24.13 KB (🟢 -3 B) 1.42 MB
/settings/spending-limits 22.72 KB (-1 B) 1.42 MB
/transactions 52.47 KB (🟡 +799 B) 1.45 MB
/transactions/history 52.43 KB (🟡 +799 B) 1.45 MB
/welcome 7.13 KB (🟡 +141 B) 1.4 MB
/welcome/social-login 7.57 KB (🟡 +138 B) 1.4 MB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

Copy link

📦 Next.js Bundle Analysis for safe-wallet-web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 1.4 MB (🟢 -493.25 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Nine Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/addOwner 3.52 KB (🟢 -2 B) 1.4 MB
/balances/nfts 18.63 KB (🟡 +1 B) 1.41 MB
/settings/security-login 14.37 KB (-1 B) 1.41 MB
/settings/setup 24.13 KB (🟢 -3 B) 1.42 MB
/settings/spending-limits 22.72 KB (-1 B) 1.42 MB
/transactions 52.47 KB (🟡 +799 B) 1.45 MB
/transactions/history 52.43 KB (🟡 +799 B) 1.45 MB
/welcome 7.13 KB (🟡 +141 B) 1.4 MB
/welcome/social-login 7.57 KB (🟡 +138 B) 1.4 MB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

@usame-algan usame-algan merged commit a272500 into dev Nov 14, 2023
14 checks passed
@usame-algan usame-algan deleted the lazyloadmpc branch November 14, 2023 15:32
@github-actions github-actions bot locked and limited conversation to collaborators Nov 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants